<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="favicon.ico">

    <title>iCloud Message</title>

    <!-- Bootstrap core CSS -->
    <link href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="http://cdn.bootcss.com/datatables/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/dashboard.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
      <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">iCloud Message</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="index.html">Users</a></li>
            <li class="active"><a href="message.html">Messages</a></li>
            <li><a href="#" data-toggle="modal" data-target="#add-form">Add New Message</a></li>
            <li><a href="#">Help</a></li>
          </ul>
        </div>
      </div>
    </nav>

    <div class="container-fluid">
      <h2 class="sub-header"></h2>
      <div class="table-responsive">
        <table class="table table-striped" id="users">
            <thead>
                <tr>
                    <th>title</th>
                    <th>location</th>
                    <th>status</th>
                    <th>guid</th>
                    <th>create_time</th>
                </tr>
            </thead>
        </table>
      </div>
    </div>

    <div id="add-form" class="modal fade" role="dialog">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">Modal title</h4>
          </div>
          <div class="modal-body">
            <form class="form-horizontal" action="">
            <fieldset>

            <!-- Text input-->
            <div class="form-group">
              <label class="col-md-4 control-label" for="title">Title</label>  
              <div class="col-md-4">
              <input id="title" name="title" type="text" placeholder="title" class="form-control input-md">
                
              </div>
            </div>

            <!-- Text input-->
            <div class="form-group">
              <label class="col-md-4 control-label" for="location">Location</label>  
              <div class="col-md-4">
              <input id="location" name="location" type="text" placeholder="location" class="form-control input-md">
                
              </div>
            </div>

            <!-- Text input-->
            <div class="form-group">
              <label class="col-md-4 control-label" for="frequency">Frequency</label>  
              <div class="col-md-4">
              <input id="frequency" name="frequency" type="text" placeholder="how many times" class="form-control input-md">
                
              </div>
            </div>

            <!-- Multiple Radios -->
            <div class="form-group">
              <label class="col-md-4 control-label" for="time">Time</label>
              <div class="col-md-4">
              <div class="radio">
<!--
                <label for="time-0">
                  <input type="radio" name="time" id="time-0" value="0" checked="checked" disabled="true">
                  All Day
                </label>
-->
              <input id="beg_datetimepicker" type="text" >
              <input id="end_datetimepicker" type="text" >
<!--
              <input id="beg_time" name="beg_time" type="text" placeholder="begin time" class="form-control input-md">
              <input id="end_time" name="end_time" type="text" placeholder="end time" class="form-control input-md">
-->
                </div>
              </div>
            </div>

            <!-- Select Basic
            <div class="form-group">
              <label class="col-md-4 control-label" for="repeat">Repeat</label>
              <div class="col-md-4">
                <select id="repeat" name="repeat" class="form-control" disabled="true">
                  <option value="0">None</option>
                </select>
              </div>
            </div>
            -->

            <!-- Select Basic 
            <div class="form-group">
              <label class="col-md-4 control-label" for="alert">Alert</label>
              <div class="col-md-4">
                <select id="alert" name="alert" class="form-control" disabled="true">
                  <option value="0">None</option>
                </select>
              </div>
            </div>
            -->

            <!-- Textarea -->
            <div class="form-group">
              <label class="col-md-4 control-label" for="invite">Invite</label>
              <div class="col-md-4">                     
                <textarea class="form-control" id="invite" name="invite" placeholder="one email a line"></textarea>
              </div>
            </div>

            <!-- Text input
            <div class="form-group">
              <label class="col-md-4 control-label" for="url">Url</label>  
              <div class="col-md-4">
              <input id="url" name="url" type="text" placeholder="" class="form-control input-md">
                
              </div>
            </div>
            -->

            <!-- Text input
            <div class="form-group">
              <label class="col-md-4 control-label" for="note">Note</label>  
              <div class="col-md-4">
              <input id="note" name="note" type="text" placeholder="" class="form-control input-md">
                
              </div>
            </div>
            -->
            </fieldset>
            </form>

          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary" id="submit">Save changes</button>
          </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="http://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="http://cdn.bootcss.com/datatables/1.10.12/js/jquery.dataTables.min.js"></script>
    <script src="http://cdn.bootcss.com/datatables/1.10.12/js/dataTables.bootstrap.min.js"></script>
    <link href="//cdn.bootcss.com/jquery-datetimepicker/2.5.4/build/jquery.datetimepicker.min.css" rel="stylesheet">
    <script src="//cdn.bootcss.com/jquery-datetimepicker/2.5.4/build/jquery.datetimepicker.full.min.js"></script>

    <!-- https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js -->
    <!-- Just to make our placeholder images work. Don't actually copy the next line! -->
    <script src="http://cdn.bootcss.com/holder/2.9.3/holder.min.js"></script>
    <script>
    $(document).ready(function() {
        $('#users').DataTable( {
            "ajax": "/messages",
            "processing": true,
            "serverSide": true,
            "columns": [
                { "data": "title" },
                { "data": "location" },
                { "data": "status" },
                { "data": "guid" },
                { "data": "create_time" }
                //{ "data": "_id" },
            ]
        });
    });

    var beg_time = '';
    var end_time = '';
    $('#beg_datetimepicker').datetimepicker({
        onChangeDateTime:function(dp,$input){
            beg_time = $input.val()
        }
    });

    $('#end_datetimepicker').datetimepicker({
        onChangeDateTime:function(dp,$input){
            end_time = $input.val()
        }
    });

    $("#submit").click(function() {
        $(this).attr("disabled", "disabled");
        var data = {};
        data.startDate = beg_time;
        data.endDate = end_time;
        data.title = $("#title").val();
        data.location = $("#location").val();
        data.invitees = $("#invite").val();
        data.frequency = $("#frequency").val();

        $.post('/post', data, function(data) {
            if(data == 'success') {
                alert("发送成功");
                $('#add-form').modal('hide')        
            }
            else {
                alert("发送失败");
            }
            $(this).attr("disabled", false);
        });

    });
    
    </script>
  </body>
</html>
